package com.zx.learn.flink.sink;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Ken.Zheng
 * @date 2023/06/04
 **/
public class SelfDefinePrintSinkDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream<Tuple2<Integer, String>> dataSource = env.fromElements(
                Tuple2.of(1, "zhangsan"),
                Tuple2.of(2, "lisi"),
                Tuple2.of(3, "wangwu"),
                Tuple2.of(4, "zhaoliu")
        );

        //获取DataStream的并行度
        int parallelism = dataSource.getParallelism();
        System.out.println("SocketSource的并行度：" + parallelism);
        //dataSource.print();
        dataSource.addSink(new SelfDefinePrintSink()).name("my-print-sink");
        env.execute();
    }
}
